#include <stdio.h>
#include <stdlib.h>

#include "link_stack.h"

LinkStack *create_ls(void)
{
    LinkStack *stack = malloc(sizeof(LinkStack));
    stack->top = NULL;
    stack->cnt = 0;
    return stack;
}

//判断是否栈空
bool empty_ls(LinkStack* stack)
{
    return NULL == stack->top;
}
//入栈
void push_ls(LinkStack* stack,void* val)
{
    Node *node = create_n(val);
    node->next = stack->top;
    stack->top = node;
    stack->cnt++;
}
//出栈
bool pop_ls(LinkStack* stack)
{
    if(empty_ls(stack))
        return false;
    Node *tmp = stack->top;
    stack->top = tmp->next;
    free(tmp);
    return stack->cnt--;
}
//销毁
void destory_ls(LinkStack* stack)
{
    while(pop_ls(stack));
    free(stack);
}
//元素长度
size_t size_ls(LinkStack *stack)
{
    return stack->cnt;
}

void *top_ls(LinkStack *stack)
{
    return stack->top->data;
}
